<template>
  <section>
    <div class="custorm--modelbox marketgroup-edit classbtn">
      <div class="renohome-right-nav flex-row flex-justify-c flex-align-c">
        <renohome-right-nav
          :custormItemData="custormItemData"
          @rightNavChange="rightNavChange"
          :showChange="'1'"
        ></renohome-right-nav>
      </div>
      <section v-if="nrActive">
        <div class="edit-form-item">
          <div class="form-label">选择拼团活动</div>
          <el-radio-group v-model="custormItemData.params.choostype" @change="clearChooseRadio">
            <el-radio label="1">按活动选择</el-radio>
            <el-radio label="2">按商品选择</el-radio>
            <el-radio label="3">自动添加</el-radio>
          </el-radio-group>
          <div
            v-if="custormItemData.params.choostype==3"
            class="inner"
          >
           <div
              class="form-label"
              style="margin-top: 20px;"
            >显示条数</div>
            <div class="flex-row flex-align-c">
              <el-slider
                :show-tooltip="false"
                style="width: 70%;margin-left:10px;"
                v-model="listitem"
                input-size="mini"
                :max="20"
                :min="1"
              >
              </el-slider>
              <div class="coupon-showslider">{{custormItemData.params.listitem}}个</div>
            </div>
          </div>
        </div>

        <div
          class="edit-form-item"
          v-if="custormItemData.params.choostype==3"
        >
          <div class="form-label">商品排序</div>
          <div>
            <el-select
              size="small"
              style="width:100%;"
              v-model="custormItemData.params.sortcustorm"
              placeholder="综合"
            >
              <el-option
                label="综合"
                value="all"
              >
              </el-option>
              <el-option
                label="按销量"
                value="sales"
              >
              </el-option>
              <el-option
                label="价格降序"
                value="desc_price"
              >
              </el-option>
              <el-option
                label="价格升序"
                value="asc_price"
              >
              </el-option>
              <el-option
                label="访问量"
                value="view_num"
              >
              </el-option>
              <el-option
                label="成交转化率"
                value="pay_num"
              >
              </el-option>
            </el-select>
          </div>
        </div>

        <div class="edit-form-item" v-if="custormItemData.params.choostype==1 || custormItemData.params.choostype==2">
          <div class="form-label mb-20">活动链接</div>
          <el-form
            label-width="50px"
            size="mini"
            class="goodsset"
            label-position="right"
            style="margin-top:20px;"
          >
            <el-form-item label="链接">
              <div class="item-inner flex-row">
                <div
                  class="readonly-div"
                  @click="uploadtoggle('link')"
                >
                  <div class="readonly ivu-input-wrapper ivu-input-wrapper-default ivu-input-type">
                    <input
                      autocomplete="off"
                      spellcheck="false"
                      type="text"
                      placeholder="请选择链接"
                      readonly="readonly"
                      class="ivu-input ivu-input-default"
                      :value="custormItemData.style.title"
                    >
                  </div> <i
                    class="icon icon-fujian readonly-icon"
                    style="left: 12px;margin-top:-3px;"
                  ></i>
                </div>
              </div>
            </el-form-item>
            <el-form-item label="" v-if="custormItemData.params.choostype==2">
              <div class="flex-row choose-item-lits">
                <div
                  v-for="(item, index) in custormItemData.data"
                  :key="index"
                  class="choose-item-child"
                >
                  <img
                    :src="item.image.file_path"
                    alt=""
                    class="small"
                  >
                  <i
                    class="delete el-icon-close"
                    @click="delItemList({data:custormItemData.data,index})"
                    style="font-size: 16px;"
                  ></i>
                </div>
              </div>
            </el-form-item>
          </el-form>
        </div>
      </section>

      <section v-if="fgActive">
        <div
          class="es-form-item goods"
          style="border-bottom: 0px;"
        >
          <div
            class="item-inner block"
            style="transform: scale(0.8) translate(-50px, -20px); width: 375px;"
          ><label
              class="button-img block"
              @click="changePattern(1)"
              v-bind:class="{active:custormItemData.style.display==1}"
              style="border-color: rgb(237, 237, 237);"
            ><input
                type="radio"
                value="style1"
                class="opacity-0"
              >

              <div class="es-seckill-group style-row">
                <div class="group">
                  <div>
                    <!-- ---- -->
                    <div
                      v-for="(item, index) in custormItemData.params.defaultData"
                      :key="index"
                      class="es-seckill-col"
                    >
                      <div class="image">
                        <img
                          :src="`${custormItemData.params.choostype == '1'?getPath('default_picture.png'):item.edit?getPath(item.edit.thumb):item.images[0]}`"
                          alt=""
                          draggable="false"
                        ><span class="group-img-btn">2人团</span></div>
                      <div class="detail">
                        <p class="title  line-hide">这里是商品标题</p>
                        <div class="subtitle line-hide flex-row flex-justify-b">
                          <span class="sub-price"><span class="icon">￥</span>0.10</span>
                        </div>
                        <div class="subtitle line-hide flex-row flex-justify-b flex-align-c">
                          <span class="sub-price line-through"><span
                              class="icon"
                              style="white-space: nowrap;"
                            >单购价:￥1.00</span></span>
                          <div class="group-btn">
                            <span class="sub-price line-through"><span class="icon">已拼20件</span></span>
                          </div>
                        </div>
                      </div>
                    </div>
                    <!-- ---- -->
                  </div>

                </div>
              </div>
            </label>
          </div>

          <div
            class="item-inner block"
            style="transform: scale(0.8) translate(-50px, -60px); width: 375px;"
          ><label
              class="button-img block"
              @click="changePattern(2)"
              v-bind:class="{active:custormItemData.style.display==2}"
              style="border-color: rgb(237, 237, 237);padding:0;"
            ><input
                type="radio"
                value="style2"
                class="opacity-0"
              >

              <div class="es-seckill-group style-col">
                <div class="group">
                  <div>
                    <!-- ---- -->
                    <div
                      v-for="(item, index) in custormItemData.params.defaultData"
                      :key="index"
                      class="es-seckill-col flex-row flex-align-c"
                    >
                      <div class="image">
                        <img
                          :src="getPath('default_picture.png')"
                          alt=""
                          draggable="false"
                        ></div>
                      <div class="detail flex-col flex-justify-b">
                        <div class="flex-col">
                          <p class="title  line-hide">这里是商品标题</p>
                          <div class="sales-num">
                            <div class="flex-row flex-align-c">
                              <div class="flex-row flex-align-c">
                                <span class="orders-gray">已拼50件</span>
                              </div>
                              <div class="subtitle line-hide">
                                <p>
                                  <span class="sales-btn">2人团</span>
                                </p>
                              </div>
                            </div>
                          </div>
                        </div>
                        <div class="sales-num col-num">
                          <div class="flex-row flex-justify-b flex-align-c">
                            <div class="flex-col">
                              <span class="sub-price"><span class="icon">￥</span>40.00</span>
                              <p class="orders-gray">单购价:￥1.00</p>
                            </div>
                            <div class="flex-row flex-align-c">
                              <div class="group-btn col-list"><span>去拼团</span></div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                    <!-- ---- -->
                  </div>

                </div>
              </div>
            </label></div>
        </div>
      </section>
    </div>
  </section>
</template>

<script>
import defaultConfig from './utils/editConfig'
import activeChoose from './utils/activeChoose'
export default {
  mixins: [defaultConfig.mixins],
  props: {
    defaultConfig: {
      type: Object,
      default: function() {
        return defaultConfig
      }
    }
  },
  computed: {
    listitem: {
      set(value) {
        this.custormItemData.params.listitem = value
      },
      get() {
        return this.conversionType('number', this.custormItemData.params.listitem)
      }
    }
  },
  mounted() { },
  methods: {
    ...activeChoose,
    uploadFileCallBack(files) {
      const { key } = files
      if (key === 'ChooseLink') {
        const { displayData = [], listData = [] } = files
        const reslut = []
        if (!listData.length) {
          const [{ groups_id, title }] = displayData
          this.custormItemData.params.link = groups_id
          this.custormItemData.style.title = title
          this.$forceUpdate()
        } else {
          listData.map((listItem) => {
            const newIndex = this.custormItemData.data.findIndex((displayItem) => {
              return `${displayItem.goods_id}` === `${listItem.goods_id}`
            })
            if (newIndex === -1) {
              reslut.push(listItem)
            }
          })
        }
        this.$set(this.custormItemData, 'data', [...this.custormItemData.data, ...reslut])
        console.log(this.custormItemData.data, 'this.custormItemData')
      }
    },
    uploadtoggle(type) {
      this.output({ type, params: { editKey: this.custormItemData.key, link_type: 'group', choose_type: this.custormItemData.params.choostype } })
    }
  }
}

</script>

<style lang="scss" scoped>
.custorm--modelbox.marketgroup-edit {
  .es-form-item {
    border-bottom: 5px solid #f6f7f9;
    padding: 20px 23px;
    font-size: 12px;

    .uploadSource {
      background: #fff;
      cursor: pointer;
    }

    .uploadSource {
      width: 50px;
      height: 50px;
      line-height: 50px;
      margin-right: 0;
      border: 1px dashed #ededed;
      text-align: center;
      color: #dad9d9;
      background-size: 100% 100%;
      background-repeat: no-repeat;
      float: left;
      position: relative;
    }
  }

  .group-btn {
    color: #fff;
    text-align: right;
    line-height: 22px;
    border-radius: 8px;
    font-size: 12px;
    height: 22px;
    &.col-list {
      background: #fd463e;
      width: 75px;
      padding: 2px 0;
      text-align: center;
      color: #fff;
      font-weight: bold;
      box-sizing: content-box;
      border-radius: 14px;
    }
  }

  .es-form-item:last-child {
    border-bottom: 0;
  }

  .es-form-item .item-inner {
    margin-top: 8px;
    position: relative;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
  }

  .es-form-item .item-inner:first-of-type {
    margin-top: 0;
  }

  .es-form-item .button-img {
    width: 32px;
    height: 32px;
    margin-right: 20px;
    cursor: pointer;
    border-radius: 4px;
    box-sizing: border-box;
    line-height: 36px;
    text-align: center;
    border: 1px solid transparent;
  }

  .es-form-item .button-img.block {
    width: 100%;
    position: relative;
    min-height: 32px;
    height: auto;
    padding: 10px;
    text-align: left;
  }

  .es-form-item .button-img.active {
    border-color: #fb6638 !important;
  }

  .es-form-item [type="checkbox"],
  [type="radio"] {
    box-sizing: border-box;
    padding: 0;
  }

  .es-form-item .opacity-0 {
    opacity: 0;
  }

  .es-form-item .button-img .opacity-0 {
    width: 0;
    height: 0;
    position: absolute;
  }

  .es-form-item .alignC {
    text-align: center;
  }

  .es-form-item .item {
    background: #f6f7f9;
    padding: 10px 20px 10px 10px;
    border: 1px solid #eee;
    color: #999;
    position: relative;
    margin-bottom: 20px;
  }

  .es-form-item .labeltext {
    width: 40px;
    text-align: right;
    padding-right: 8px;
    color: #666;
  }

  .readonly-div {
    position: relative;
    flex-grow: 1;
  }

  .ivu-input-wrapper {
    display: inline-block;
    width: 100%;
    position: relative;
    vertical-align: middle;
    line-height: normal;
  }

  .ivu-input {
    display: inline-block;
    width: 100%;
    height: 32px;
    line-height: 1.5;
    padding: 4px 12px;
    font-size: 12px;
    border: 1px solid #ededed;
    border-radius: 4px;
    color: #333;
    background-color: #fff;
    background-image: none;
    position: relative;
    cursor: text;
    -webkit-transition: border 0.2s ease-in-out, background 0.2s ease-in-out,
      -webkit-box-shadow 0.2s ease-in-out;
    transition: border 0.2s ease-in-out, background 0.2s ease-in-out,
      box-shadow 0.2s ease-in-out;
  }

  .readonly-div .readonly input {
    background: #e8effc;
    border: 0;
    padding-left: 18px;
    cursor: pointer;
    box-sizing: border-box;
  }

  .readonly-div .readonly-icon {
    position: absolute;
    top: 5px;
    left: 12px;
  }

  .es-form-item .item .delete-child {
    position: absolute;
    right: 4px;
    top: 0;
    cursor: pointer;
    font-size: 14px;
  }

  //列表结束

  .edit-form-item {
    border-bottom: 5px solid #f6f7f9;
    padding: 20px 23px;
    font-size: 12px;
  }

  .edit-form-item:last-child {
    border-bottom: 0;
  }

  .el-radio__label {
    font-size: 12px;
  }

  .el-checkbox__label {
    font-size: 12px;
  }

  .form-label {
    line-height: 1;
    color: #47565d;
    font-weight: bolder;
    margin-bottom: 20px !important;
  }

  .inner {
    margin-top: 12px;
    white-space: nowrap;
  }

  .goodscol-add {
    border: 1px dashed #6b7685;
    line-height: 32px;
    height: 32px;
    border-radius: 4px;
    text-align: center;
    cursor: pointer;
  }

  .stylebox {
    background: #f6f7f9;
    padding: 10px 20px;
    border: 1px solid #eee;
    color: #999;
    margin-top: 30px;
    white-space: nowrap;
  }

  .txbox {
    border-radius: 3px;
    border: 1px solid transparent;
    margin: 0 15px 0 13px;
    padding: 5px;
    cursor: pointer;
  }

  .txbox.active {
    border-color: #fb6638;
  }

  .zft {
    background: #dcdcdc;
    height: 15px;
    width: 15px;
    border-radius: 3px;
  }

  .cft {
    background: #dcdcdc;
    height: 15px;
    width: 25px;
    border-radius: 3px;
  }

  .yuan {
    background: #dcdcdc;
    height: 15px;
    width: 15px;
    border-radius: 15px;
  }

  .select-btn-box {
    background: #e8effc;
    cursor: pointer;
    border-radius: 5px;
    padding: 0 10px;
    height: 32px;
    line-height: 32px;
    width: 60%;
  }

  .select-btn-icon {
    line-height: 32px;
    float: left;
    margin-right: 5px;
  }

  .select-btn-text {
    line-height: 32px;
    display: inline-block;
    height: 32px;
    vertical-align: middle;
  }

  .el-slider__input {
    width: 105px;
  }

  .el-slider__runway.show-input {
    margin-right: 130px;
  }

  //风格
  .es-form-item .item-inner:first-of-type {
    margin-top: 0;
  }

  .es-form-item .item-inner {
    margin-top: 8px;
    position: relative;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
  }

  .block {
    display: block !important;
  }

  .es-form-item {
    border-bottom: 5px solid #f6f7f9;
    padding: 20px 23px;
    font-size: 12px;
  }

  .es-form-item.goods .button-img {
    padding: 0;
  }

  .button-img.block {
    width: 100%;
    position: relative;
    min-height: 32px;
    height: auto;
    padding: 10px;
    text-align: left;
  }

  .button-img {
    width: 32px;
    height: 32px;
    margin-right: 20px;
    cursor: pointer;
    border-radius: 4px;
    line-height: 36px;
    text-align: center;
    border: 1px solid transparent;
  }

  .flex,
  .flex-column {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
  }

  .es-seckill-group {
    line-height: 1;
  }

  .es-seckill-title {
    margin: 20px 20px 6px;
    height: 22px;
    font-size: 11px;
    -webkit-box-pack: justify;
    -webkit-justify-content: space-between;
    -ms-flex-pack: justify;
    justify-content: space-between;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
  }

  .es-seckill-title .title {
    .seckill-title {
      font-size: 16px;
      font-weight: 700;
      color: #3d404d;
      background: #fff;
    }

    font-size: 16px;

    img {
      vertical-align: middle;
      zoom: 0.5;
    }

    & + p {
      color: #999;
      margin-right: -5px;
    }
  }

  .es-seckill-title span {
    background: #fff;
    display: inline-block;
    color: #333;
    text-align: center;
    line-height: 18px;
    width: 17px;
  }

  .es-seckill-title span:first-of-type {
    width: auto;
    background: #fe504f;
    color: #fff;
    font-size: 12px;
    margin-right: 8px;
    padding: 1px 3px;
  }

  .es-seckill-group.style-row .group {
    overflow: hidden;

    & > div {
      font-size: 0;
    }
  }

  .es-seckill-group.style-row .group .es-seckill-col {
    display: inline-block;
    padding: 20px 0 0 20px;
    width: 168px;
    box-sizing: border-box;
    border-radius: 2px;

    &:nth-of-type(even) {
      margin-left: 10px;
    }

    .image {
      position: relative;
      height: 141px;
      margin: 4px 0 8px;
      width: 100%;
      border: 1px solid #e5e5e5;
      border-radius: 10px;
      .group-img-btn {
        display: block !important;
        position: absolute;
        background: -webkit-gradient(
          linear,
          left top,
          right top,
          from(#fe504f),
          to(#fe854f)
        );
        background: -o-linear-gradient(left, #fe504f, #fe854f);
        background: linear-gradient(90deg, #fe504f, #fe854f);
        border-radius: 3px 0 3px 0;
        top: 10px;
        left: 0;
        height: 18px;
        line-height: 19px;
        width: 36px;
        color: #fff;
        text-align: center;
        font-size: 12px;
      }
      img {
        height: 139px;
        width: 146px;
        object-fit: cover;
        display: block;
      }
    }
  }

  .es-seckill-group.style-row .group .es-seckill-col .detail {
    width: 100%;
    font-size: 12px;
    padding-bottom: 20px;

    .title {
      height: 40px;
      font-size: 14px;
    }

    .subtitle {
      height: 24px;
      line-height: 1;

      .sub-price {
        font-size: 14px;

        .icon {
          font-size: 12px;
        }

        &:not(.line-through) {
          font-size: 20px;
          color: #fd463e;
          font-weight: 600;
        }

        &.line-through {
          color: #999;
          text-decoration: none;
        }
      }
    }

    .sales-num {
      .num {
        font-size: 14px;
        color: #999;
      }

      .progress {
        width: 50px;
        height: 10px;
        border-radius: 10px;
        line-height: 10px;
        background: rgb(242, 242, 242);

        .progress-num {
          display: inline-block;
          background: #fd463e;
          width: 40%;
          height: 10px;
          border-radius: 10px;
        }
      }
    }
  }

  .es-seckill-group.style-row .group .es-seckill-col .detail .price .num {
    color: #999ca7;
    font-size: 9px;
    line-height: 25px;
    margin-left: 6px;
  }

  .es-seckill-group.style-row .group .es-seckill-col .detail .price .flex {
    -webkit-box-pack: start;
    -webkit-justify-content: flex-start;
    -ms-flex-pack: start;
    justify-content: flex-start;
  }

  .es-seckill-group.style-row .group .es-seckill-col .detail .price span {
    font-size: 16px;
  }

  .es-seckill-group.style-col .group {
    overflow: hidden;

    & > div {
      white-space: nowrap;
      font-size: 0;
    }
  }

  .es-seckill-group.style-col .group .es-seckill-col {
    padding: 15px;
    box-sizing: border-box;
    border-radius: 2px;
    // border-bottom: 1px solid #999;
    padding-bottom: 12px;

    .image {
      position: relative;
      height: 125px;
      width: 125px;
      margin: 4px 0 4px;
      border-radius: 5px;

      img {
        height: 100%;
        width: 100%;
        object-fit: cover;
        border-radius: 10px;
        display: block;
      }
    }
  }

  .es-seckill-group.style-col .group .es-seckill-col .detail {
    width: 0;
    flex-grow: 1;
    font-size: 12px;
    margin-left: 15px;
    margin-right: 0;
    height: 135px;
    .title {
      font-size: 14px;
      // height: 40px;
      margin-bottom: 8px;
      // overflow: hidden;
      text-overflow: ellipsis;
      width: 215px;
    }
    .sales-num.col-num {
      padding-bottom: 10px;
      border-bottom: 0.5px solid #e5e5e5;
    }
    .sub-price {
      font-size: 14px;

      .icon {
        font-size: 12px;
      }

      &:not(.line-through) {
        font-size: 18px;
        line-height: 1.5;
        color: #fd463e;
        font-weight: 600;
      }

      &.line-through {
        color: #999;
        text-decoration: line-through;
      }
    }
    .progress-box {
      position: relative;
      height: 15px;
      margin-bottom: 15px;

      .progress {
        width: 55%;
        height: 15px;
        border-radius: 10px;
        line-height: 16px;
        text-align: center;
        background-color: #f7cfcd;

        .progress-num {
          color: #fff;
          display: inline-block;
          height: 15px;
          border-radius: 10px;
        }
      }
    }

    .sales-num {
      .sales-btn {
        margin-left: 4px;
        border: 1px solid #fd463e;
        color: #fd463e;
        padding: 0 6px;
        border-radius: 4px;
        font-size: 14px;
        height: 26px;
      }
    }
  }

  .es-seckill-group.style-col .group .es-seckill-col .detail .price .num {
    color: #999ca7;
    font-size: 9px;
    line-height: 25px;
    margin-left: 6px;
  }

  .es-seckill-group.style-col .group .es-seckill-col .detail .price .flex {
    -webkit-box-pack: start;
    -webkit-justify-content: flex-start;
    -ms-flex-pack: start;
    justify-content: flex-start;
  }

  .es-seckill-group.style-col .group .es-seckill-col .detail .price span {
    font-size: 16px;
  }
}
.classbtn{
  /deep/ .el-radio{
    margin-right: 0;
  }
}
</style>
